package com.code;

public class TenTo52 {


    static char[] hex52Table = new char[52];
    static char[] hex16Table = new char[16];

    static {
        int i = 0;
        for (; i < 26; i++) {
            hex52Table[i] = (char) (65 + i);
        }
        for (; i < 52; i++) {
            hex52Table[i] = (char) (97 + i - 26);
        }

        for (i = 0; i < 10; i++) {
            hex16Table[i] = (char) (i + 48);
        }
        for (; i < 16; i++) {
            hex16Table[i] = (char) (65 + i - 10);
        }

    }

    public static void main(String[] args) {
        tenToHex(124223223);
        tenToNHex(12432323,52);
    }

    public static void tenToHex(long l) {
        StringBuilder sb = new StringBuilder();
        byte tmp = 0;
        for (int i = 0; i < 16; i++) {
            tmp = (byte) (tmp | ((byte) l));
            sb.insert(0, hex16Table[tmp & 0xF]);
            tmp = 0;
            l = l >> 4;
        }
        System.out.println(sb.insert(0, "0x"));
    }

    public static void tenToHex2(long l) {

        long y;

        StringBuilder sb = new StringBuilder();
        while (l > 0) {
            y = l % 16;
            sb.insert(0, hex16Table[(int) y]);
            l = l / 16;
        }
        System.out.println(sb.insert(0, "0x"));

    }

    public static void tenToNHex(long l, int hex) {
        long y;
        StringBuilder sb = new StringBuilder();
        while (l > 0) {
            y = l % hex;
            sb.insert(0, hex52Table[(int) y]);
            l = l / hex;
        }
        sb.insert(0, "x");
        sb.insert(0, hex);
        System.out.println(sb);
    }

}
